package com.zhang.zhangapp.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhang.zhangapp.R;

import java.util.List;
import java.util.Map;

public class BankTypeAdapter extends BaseAdapter {
    private Context context;
    private List<Map<String, String>> typeList;

    public BankTypeAdapter(Context context, List<Map<String, String>> typeList) {
        this.context = context;
        this.typeList = typeList;
    }

    @Override
    public int getCount() {
        return typeList == null ? 0 : typeList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_bank_type, null);
        TextView textView = view.findViewById(R.id.bank_type);
        textView.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(getImageSrc(typeList.get(i).get("code"))), null, null, null);
        textView.setText(typeList.get(i).get("name"));
        return view;
    }

    private int getImageSrc(String code) {
        if (code.equals("001"))
            return R.mipmap.china_bank;
        if (code.equals("004"))
            return R.mipmap.icbc_bank;
        if (code.equals("002"))
            return R.mipmap.construction_bank;
        if (code.equals("003"))
            return R.mipmap.agr_bank;
        if (code.equals("010"))
            return R.mipmap.communications_back;
        if (code.equals("005"))
            return R.mipmap.merchants_bank;
        if (code.equals("007"))
            return R.mipmap.industrial_bank;
        if (code.equals("008"))
            return R.mipmap.ltd_bank;
        if (code.equals("009"))
            return R.mipmap.pufa_bank;
        if (code.equals("006"))
            return R.mipmap.guangda_bank;
        if (code.equals("011"))
            return R.mipmap.youzheng_bank;
        return R.mipmap.no_icon_bank;
    }
}
